home *** CD-ROM | disk | FTP | other *** search
/ ETO Development Tools 2 / ETO Development Tools 2.iso / Tools - Objects / ResEdit / ResEdit 2.0b2 / Examples / CExamples / Source / ICON.Pick.c < prev    next >
Encoding:
C/C++ Source or Header  |  1990-04-02  |  4.0 KB  |  146 lines  |  [TEXT/MPS ]

  1. /*
  2.  COPYRIGHT (C) 1984-1990 Apple Computer,Inc.
  3.  All rights reserved
  4. */
  5.  
  6. /* Icon Resource Picker */
  7.  
  8. /* This is the Icon resource picker.  This picker is very similar to all other pickers.
  9.         The general scheme is that a List structure is created whose cells
  10.         contain the ID's of this resource type.  A drawproc is installed in the List
  11.         record which is called to display the resource.  Obviously, graphical resources
  12.         are drawn as is, but descriptions of other types can be displayed also (usually
  13.         in a one-dimensional list). */
  14.  
  15. #include    <types.h>
  16. #include    <memory.h>
  17. #include    <menus.h>
  18. #include    <resources.h>
  19. #include    <lists.h>
  20.  
  21. #include    "ResEd.h"
  22.  
  23. #define listCellSizeH             0x38
  24. #define listCellSizeV                0x42
  25.     
  26. /* Needs to be 2 wide so that I can always tell a 2 dimensional list from a normal text list. */
  27. #define minIconsPerRow             2
  28. #define ICONMinWindowWidth     (minIconsPerRow * listCellSizeH) + theScrollBar
  29. #define ICONMinWindowHeight listCellSizeV
  30.     
  31. #define ICONResourceSize         128
  32.  
  33.  
  34. /* Used only for editors. */
  35. pascal void EditBirth(Handle thing, ParentHandle dad)
  36. {
  37.     #pragma    unused (thing, dad)
  38. }
  39.  
  40. /* *********************************************************************************** */
  41.  
  42. /* Returns the width and the iconsPerRow. */
  43. short GetWidth (short *iconsPerRow)
  44. {
  45.     short width;
  46.  
  47.     width = PickStdWidth();
  48.     if (width > ICONMinWindowWidth) {
  49.         *iconsPerRow = (width - theScrollBar) / listCellSizeH;
  50.         width = (*iconsPerRow * listCellSizeH) + theScrollBar;
  51.         }
  52.     else {
  53.         width = ICONMinWindowWidth;
  54.         *iconsPerRow = minIconsPerRow;
  55.         }
  56.     return width;
  57. }
  58.  
  59. /* *********************************************************************************** */
  60.  
  61. short GetHeight (void)
  62. {
  63.     short height;
  64.     
  65.     height = PickStdHeight();
  66.     if (height > ICONMinWindowHeight) {
  67.         height = (height / listCellSizeV) * listCellSizeV;
  68.         }
  69.     else {
  70.         height = ICONMinWindowHeight;
  71.         }
  72.     return height;
  73. }
  74.  
  75. /* *********************************************************************************** */
  76.  
  77. pascal void PickBirth(ResType t, ParentHandle dad)
  78. {
  79.     PickHandle     pick;
  80.     PickPtr            p;                    /* temp ptr for *pick */
  81.     short                iconsPerRow,
  82.                             width;
  83.  
  84.  
  85.     pick = (PickHandle)NewHandle(sizeof(PickRec));
  86.  
  87.     p = *pick;
  88.  
  89.     p->father = dad;                                     /* Back ptr to dad                                                                             */
  90.     p->rType = t;                                         /* Resource type that I understand                                             */
  91.     p->viewBy = viewBySpecial;                /* Special means we have our own LDEF to draw the icons */
  92.     p->ldefType = t;                                    /* Which LDEF do we use? */
  93.     p->cellSize.h = listCellSizeH;        /* Set the size of the cell.                                                        */
  94.     p->cellSize.v = listCellSizeV;
  95.  
  96.     width = GetWidth (&iconsPerRow);    /* Also sets iconsPerRow */
  97.  
  98.   // Setup the list and create the window.
  99.     if (!DoPickBirth(false, true, width, GetHeight(), iconsPerRow, ResEdID(), pick)) {
  100.         DisposHandle ((Handle)pick);        // Error
  101.     }
  102.     else {
  103.         (*pick)->rSize = ICONResourceSize;
  104.         }
  105. }
  106. /* *********************************************************************************** */
  107.  
  108. /* Everything except the grow box is taken care of for us by PickEvent. */
  109. pascal void DoEvent(EventRecord *evt, PickHandle pick)
  110. {
  111.     WindowPtr windPtr;
  112.     
  113.     /* Must do our own grow box manipulation so that the min size is set correctly. */
  114.     if ((evt->what == mouseDown) && (FindWindow(evt->where, &windPtr) == inGrow)) {
  115.         GrowMyWindow (ICONMinWindowWidth, ICONMinWindowHeight, windPtr, (*pick)->instances);
  116.         }
  117.     else {
  118.         PickEvent(evt, pick);
  119.         }
  120. }
  121.  
  122. /* *********************************************************************************** */
  123.  
  124. /* Everything is taken care of for us by PickInfoUp */
  125. pascal void DoInfoUpdate(short oldID, short newID, PickHandle pick)
  126. {
  127.     PickInfoUp(oldID, newID, pick);
  128. }
  129.  
  130. /* *********************************************************************************** */
  131.  
  132. pascal Boolean IsThisYours (Handle thing, PickHandle pick)
  133.  
  134. {
  135.     #pragma    unused (thing, pick)
  136.     return false;
  137. }
  138.  
  139. /* *********************************************************************************** */
  140.  
  141. pascal void DoMenu(short menu, short item, PickHandle pick)
  142. {
  143.     /* Everything is taken care of for us by PickMenu.                                                                      */
  144.     PickMenu(true, menu, item, pick);
  145. }
  146.